// pages/my-server-drive/index.js
// 获取应用实例
const app = getApp()
import {
    util,
    Toast,
    commonMixin
} from "../../utils/util.js";
Page({
    behaviors: [commonMixin],
    data: {
        isend: false,
        page: 1,
        category: {
            name: ''
        },
        dataList: [],
    },
    onLoad(options) {
        // this.setData({
        //     isend: false,
        //     page: 1,
        //     dataList: []
        // })
        // this.getDataList();
        let id = options.id;
        wx.showLoading({
            title: '加载中',
          })
          util.http.post("v1/mini/question-get-list",{
              id: id
          }).then((res) => {
              if (res.data.code == 0) {
                this.setData({
                    category: res.data.data.category,
                    dataList: res.data.data.list,
                })
                wx.setNavigationBarTitle({
                  title: this.data.category.name,
                })
              }
              wx.hideLoading();
          }).catch((err) => {
              wx.hideLoading();
              Toast('网络异常！刷新后重试！');
              console.log(err)
          })
    },
    onShow() {

    },
    //获取活动数据
    getDataList() {
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        let userInfo = util.getUserInfo();
        util.http.get("applet/activity", {
            limit: 20,
            page: this.data.page,
            info_id: userInfo.id
        }).then((res) => {
            if (res.data.code == 0) {
                //合并数据
                let dataList = [...this.data.dataList, ...res.data.data.list];
                this.setData({
                    dataList
                })

                //上拉刷新
                if (res.data.data.list && res.data.data.list.length > 0) {
                    let page = this.data.page;
                    this.setData({
                        page: page + 1
                    })
                } else {
                    if (this.data.page != 1) {
                        this.setData({
                            isend: true
                        })
                    }
                }

            } else {
                Toast(res.data.message);
            }
            wx.hideLoading();
        }).catch((err) => {
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if (!this.data.isend) {
            this.getDataList();
        }
    },
    onShareAppMessage() {
     
    },
})